export const getDynamicMenuRouters = function (menus=[],routes=[]) {
    let singleRoute = [];
    let childrenRoute = {};
    for (let i = 0; i < menus.length; i++) {
        if (menus[i].children && menus[i].children.length > 0) {
            childrenRoute = createRoute(menus[i])
            childrenRoute.children = getDynamicMenuRouters(menus[i].children)
            routes.push(childrenRoute)
        } else {
            /* 只有一级路由的 */
            singleRoute.push(createRoute(menus[i]))
        }
    }
    return routes.concat(singleRoute)
}

/* 将菜单生成 route */

function createRoute(menu){
    let route = {
        path: menu.path,
        name: menu.name,
        component:(resolve) => require([`@views${menu.path}`],resolve),
        meta:menu.meta,
    }
    if (menu?.children && menu.children.length >0 ) {
        route.children = []
    }
    return route
}